#include <iostream>
#include <pthread.h> //Linux 原生线程库
#include <unistd.h>

#define N 5
#define SIZE 1024
using namespace std;

void* threadRoutine(void* arg)
{
    while(true)
    {
        printf("%s -> pid: %d ppid: %d\n", (char*)arg, getpid(), getppid());
        //printf("%s success!\n", (char*)arg);
        sleep(1);
    }
    return 0;
}

int main()
{
    pthread_t pid[5];
    for(int i = 0; i < N; ++i)
    {
        char buffer[SIZE] = {0};
        //char* buffer = new char[64];
        sprintf(buffer, "thread %d", i);
        int n = pthread_create(&pid[i], nullptr, threadRoutine, buffer);  
        if(n != 0)
        {
            perror("main::pthread_create");
            return 1;
        }
    }

    while(true)
    {
        //printf("I am main thread!!!\n");
        printf("main thread -> pid: %d ppid: %d\n", getpid(), getppid());
        sleep(1);
    }

    return 0;
}